package org.replay.controller;

/*
 * Copyright © 2020 lizicong,All rights reserved.
 *
 * Licensed under the GPL License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import io.lettuce.core.api.sync.RedisCommands;
import org.apache.curator.framework.CuratorFramework;
import org.replay.repository.RedisDynamicCommands;
import org.replay.service.SeckillCommodityService;
import org.replay.utils.RabbitACKSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 系统参数调节控制器
 * @author lizicong
 */

@RestController("/sys")
public class SystemController {

    /**
     * lettuce动态命令客户端
     * 未限制读操作
     */
    @Resource
    RedisDynamicCommands redisDynamicCommands;

    @Resource
    SeckillCommodityService seckillCommodityService;

    final static String REDIS_PREFIX = "SECKILL_STOCK_COMMODITY_";
    final static String REDIS_SUFFIX = "_BOUGHT_USER_ID";

    /**
     * 缓存预热，只能在活动开始前使用
     * 我知道按照三层架构规范不应该把逻辑写在控制器，我觉得只是临时用的，按简单来的就行。
     *
     * @param code
     */
    @GetMapping("/nodePreheat")
    public void nodePreheat(@RequestParam("code") String code) {

        //简单的权限校验
        if (!code.equals("admin123"))
            return;
        seckillCommodityService.nodePreheat();
    }
}
